﻿using System;
using System.ComponentModel.DataAnnotations;
using Volo.Abp.Domain.Entities;

namespace Demo.Identity.Permissions.Entities;

/// <summary>
/// 权限实体类
/// </summary>
public class SysPermission : Entity<Guid>
{
    /// <summary>
    /// 服务名称
    /// </summary>
    [MaxLength(64)]
    public string ServiceName { get; set; }

    /// <summary>
    /// 权限编码
    /// </summary>
    [MaxLength(128)]
    public string Code { get; set; }

    /// <summary>
    /// 权限名称
    /// </summary>
    [MaxLength(64)]
    public string Name { get; set; }

    /// <summary>
    /// 上级权限ID
    /// </summary>
    [MaxLength(128)]
    public string ParentCode { get; set; }


    /// <summary>
    /// 判断两个权限是否相同
    /// </summary>
    /// <param name="obj"></param>
    /// <returns></returns>
    public override bool Equals(object? obj)
    {
        return obj is SysPermission permission
               && permission.ServiceName == ServiceName
               && permission.Name == Name
               && permission.Code == Code
               && permission.ParentCode == ParentCode;
    }

    /// <summary>
    /// 设置ID的值
    /// </summary>
    /// <param name="id"></param>
    public void SetId(Guid id)
    {
        Id = id;
    }
}